package com.liaoye.hellocustomview.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.view.View;

public class PathView extends View {
    public PathView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        //设置画布变黑
        canvas.drawColor(0xff000000);


        //设置画笔的基本属性
        Paint paint=new Paint();
        //设置画笔颜色
        paint.setColor(Color.RED);
        //设置填充样式
        paint.setStyle(Paint.Style.STROKE);
        //设置画笔宽度
        paint.setStrokeWidth(5);

        Path path = new Path();

        //设置起点
        path.moveTo(10, 10);
        path.lineTo(10, 100);
        path.lineTo(300, 100);
        path.close(); //闭环

        canvas.drawPath(path, paint);


        Path path1 = new Path();

        path1.moveTo(400, 10);

        //先画一个椭圆 然后根据角度截取椭圆的边就成了圆弧
        RectF rectF = new RectF(400, 10, 500, 100);

        //从角度0到角度90度,并且强制将弧的起点作为绘制开始位置
        path1.arcTo(rectF, 0, 90, true);

        canvas.drawPath(path1, paint);

        Paint paint2 = new Paint();
        paint2.setColor(Color.GREEN);
        paint2.setStyle(Paint.Style.FILL);

        Path path2 = new Path();
        path2.addRect(100, 600, 300, 800, Path.Direction.CW);
        path2.addCircle(300, 800, 100, Path.Direction.CW);

        //Path.FillType.WINDING 默认值  PATH全部显示
        //Path.FillType.INVERSE_WINDING 取PATH的外部区域
        //Path.FillType.EVEN_ODD 取Path所在的并不相交的区域
        //Path.FillType.INVERSE_EVEN_ODD 取Path外部区域和相交区域
        path2.setFillType(Path.FillType.INVERSE_EVEN_ODD);
        canvas.drawPath(path2, paint2);
    }
}
